package org.smartstruts.taglib;

import java.io.IOException;
import java.util.ResourceBundle;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import org.smartstruts.Globals;

/**
 * 自定义标记类
 * 
 * @author Wangpeihu
 * @team [Never give up]
 * @since JDK1.6(建议)
 */
public class MessageTag extends SimpleTagSupport {
	private String key;

	@Override
	public void doTag() throws JspException, IOException {
		PageContext pageCtx = (PageContext) this.getJspContext();

		// 有了pageContext就有了一切的隐含对象的入口
		ResourceBundle rb = (ResourceBundle) pageCtx.getRequest().getAttribute(
				Globals.KEY_MESSAGE_RESOURCES);

		String msg = rb.getString(key);
		pageCtx.getOut().write(msg);
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}
}
